package cn.tedu.hospitalqd.controller;

import cn.tedu.hospitalqd.pojo.dto.PatientAddNewDTO;
import cn.tedu.hospitalqd.pojo.vo.PatientListItemVO;
import cn.tedu.hospitalqd.pojo.vo.PatientStandarVO;
import cn.tedu.hospitalqd.service.PatientService;
import cn.tedu.hospitalqd.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@SuppressWarnings("ALL")
@Slf4j
@RestController
@RequestMapping("/patients")
@Api(tags="01.患者的详细信息")
@Validated
public class PatientController {
    @Autowired
    private PatientService patientService;

    @PostMapping("/add-new")
    @ApiOperation("添加患者")
    @ApiOperationSupport(order=100)
    public JsonResult addNew(@Valid PatientAddNewDTO patientAddNewDTO){
        log.debug("开始处理【添加患者】的请求，参数：{}", patientAddNewDTO);
        patientService.addNew(patientAddNewDTO);
        return JsonResult.ok();
    }
    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("根据ID删除患者")
    @ApiOperationSupport(order=200)
    @ApiImplicitParams(value ={
            @ApiImplicitParam(name = "id",value = "患者ID",required = true,dataType ="long" )
    })
    public JsonResult delete(@Range(min=1,message = "删除患者失败，ID值无效！")
                             @PathVariable Long id){
        patientService.delete(id);
        return JsonResult.ok();
    }
    @PostMapping("/{id:[0-9]+}/update")
    @ApiOperation("修改患者详情")
    @ApiOperationSupport(order=410)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "患者ID", required = true, dataType = "long")
    })
    public JsonResult updateInfoById(@Range(min = 1, message = "获取患者详情失败，ID值无效！")
                                      @PathVariable Long id) {
        PatientStandarVO queryResult = patientService.getStandardById(id);
        return JsonResult.ok(queryResult);
    }
    @GetMapping("/{id:[0-9]+}")
    @ApiOperation("根据ID查询患者详情")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "患者ID", required = true, dataType = "long")
    })
    public JsonResult getStandardById(@Range(min = 1, message = "获取患者详情失败，ID值无效！")
                                      @PathVariable Long id) {
        PatientStandarVO queryResult = patientService.getStandardById(id);
        return JsonResult.ok(queryResult);
    }
    @GetMapping("")
    @ApiOperation("查询患者列表")
    @ApiOperationSupport(order=420)
    public JsonResult list(){
        List<PatientListItemVO> list=patientService.list();
        return JsonResult.ok(list);

        }
    }

